<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    *{margin: 0;padding: 0;}
    ul{list-style: none;}
    .container ul li{
        width: 100%;
        height: 600px;
        text-align: center;
        border-top: 1px solid #ccc;
    }
    .scroll{
        background: rgb(155, 235, 139);
        width: 100px;
        height: 500px;
        position: fixed;
        right: 100px;
        bottom: 100px;
        display: none;
    }
    .scroll ul li{
        width: 100%;
        height: 100px;
        line-height: 100px;
        text-align: center;
        font-size: 20px;
    }
    </style>
</head>
<body>
<div class="container"">
    <ul>
        <li>头部</li>
        <li>banner</li>
        <li>图书</li>
        <li>服装</li>
        <li>宠物</li>
        <li>电子</li>
    </ul>
</div>
<div class="scroll">
    <ul>
        <li>图书</li>
        <li>服装</li>
        <li>宠物</li>
        <li>电子</li>
        <li>回到顶部</li>
    </ul>
</div>
<script src="js/jquery-3.6.0.min.js"></script>
<script>
$(function(){
    $(window).scroll(function(){
        if($(window).scrollTop()>$(window).height()){
            $(".scroll").show();
        }else{
            $(".scroll").hide();
        }
    })
    $(".scroll ul li").click(function(){
        var idx=$(this).index();
        if(idx==4){
            //$(window).scrollTop(0);
            //兼容
            $(document.body).animate({"scrollTop":0},1000);
            $(document.documentElement).animate({"scrollTop":0},1000);
        }else if(idx==0){
            $(document.body).animate({"scrollTop":1200},1000);
            $(document.documentElement).animate({"scrollTop":1200},1000);
            
        }else if(idx==1){
            $(document.body).animate({"scrollTop":1800},1000);
            $(document.documentElement).animate({"scrollTop":1800},1000);
            
        }else if(idx==2){
            $(document.body).animate({"scrollTop":2400},1000);
            $(document.documentElement).animate({"scrollTop":2400},1000);
            
        }else if(idx==3){
            $(document.body).animate({"scrollTop":3000},1000);
            $(document.documentElement).animate({"scrollTop":3000},1000);
            
        }
    })

  
})
</script>
</body>
</html>